<?php
class Testimonial_model extends CI_Model {

	function getTestimonials(){
		return $this->db->query("SELECT * FROM mlme_testimonials");
	}

	function getTestimonials_limited($start_row=0, $limit=10){
		$query = $this->db->query("SELECT a.*,b.firstname,b.lastname FROM mlme_testimonials as a LEFT JOIN mlme_users as b ON a.userid = b.userid ORDER BY testimonialid DESC LIMIT $start_row, $limit");
		return $query->result();
	}

	function get_userid($email){
		 $query = $this->db->query("SELECT userid FROM mlme_users WHERE email ='".$email."'");
		 $result = $query->row();
		 return $result->userid;
	}

	function addTestimonials(){
		$userid = $this->get_userid($_SESSION['email']);
		$new_testimonial = array(
			'userid' => $userid,
			'testimonial' => $this->input->post('testi-message'),
			'date_added' => date('F j, Y'),
			'status' => '0'
		 	);
		$insert = $this->db->insert('mlme_testimonials', $new_testimonial);
		return $insert;
	}



}// end of Model


